
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_hotwork/bean/BaseBean.dart';
import 'package:flutter_hotwork/bean/PointRecordBean.dart';
import 'package:flutter_hotwork/homepage/BaseTitleBar.dart';
import 'package:flutter_hotwork/homepage/BaseViewBar.dart';
import 'package:flutter_hotwork/utils/DioUtils.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:sticky_headers/sticky_headers/widget.dart';

import '../Myapplication.dart';
import '../Toast.dart';
var firstrefresh =0;
PointRecordBean recordBean=new PointRecordBean();
class PointRecordScreen extends StatefulWidget {
  @override
  PointRecordState createState() => new PointRecordState();


}

class PointRecordState extends State<PointRecordScreen> {


  void getPonitRecord() async {
    try {
      Response response;

        response = await DioUtils.dio.get(
            DioUtils.API_PREFIX + "/checkTask/listAppChekTaskAreaClock?checkUser="+MyApplication.loginuserinfo.userInfo.username);



      Map respMap = json.decode(response.data);
      recordBean = PointRecordBean.fromJson(respMap);
      if(firstrefresh==0){
        setState(() {
        });
      }
      print('响应数据：' + response.toString());
    } catch (e) {
      //  LocalToast.toast(context,msg: "网络错误");
      print('请求出错：' + e.toString());
    }
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getPonitRecord();
  }
  @override
  Widget build(BuildContext context) {



    ScrollController controller = ScrollController();

    double rpx = MediaQuery
        .of(context)
        .size
        .width / 750;
    return Scaffold(
      appBar: new BaseViewBar(
          childView: new BaseTitleBar(
            "区域打卡记录",
            leftIcon: 'images/fanhui.png',
            rightIcon:  '',
            rightClick: () {
            },
            leftClick: () {
              print("点击了左边干嘛啊。。。哦");
              Navigator.of(context).pop();
            },
          ),
          preferredSize: Size.fromHeight(50.0)),
      body:
      Container(
          color: Colors.white,
        child:
            Column(children: [
              null!=recordBean.result?
            Expanded(
              child:
              genContentList(recordBean.result,context, controller)
            ):Container()
              ,
            ],)
      ),

    );
  }


  genContentList(List<Result> data, BuildContext context, controller){
    double rpx = MediaQuery.of(context).size.width / 750;
    return ListView.builder(
        shrinkWrap: true,
        controller: controller,
        itemCount: data.length,
        itemBuilder:(BuildContext context, int index){
          return Container(


            // decoration: BoxDecoration(
            //   color: Colors.white,
            //   boxShadow: <BoxShadow>[//设置阴影
            //     new BoxShadow(
            //       color: Colors.grey,//阴影颜色
            //       blurRadius:1.0,//阴影大小
            //     ),
            //   ],
            // ),

            margin: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:10),
            // height: 260 * rpx,
            child: Column(
              children: <Widget>[
                Container(
                  height: 10,
                ),
                Container(
                  padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:0),
                  child: Row(
                    crossAxisAlignment:CrossAxisAlignment.center,
                    children: [
                      Container(
                        width: 10,
                      ),
                      Text("区域名称："+data[index].areaName,style: new TextStyle(color: Color(0xFF333333),
                        fontSize: 14.0,
                      ),
                        maxLines: 3,
                        softWrap: true,
                      ),
                      Flexible(fit: FlexFit.tight, child: SizedBox()),

                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:0),
                  margin: EdgeInsets.only(left: 0,top: 10,right: 0,bottom: 10),
                  child: Row(
                    children: [
                      // Image(height:20,width: 20,image: AssetImage('images/mingcheng.png')),
                      Container(
                        width: 10,
                      ),
                      Expanded(
                        child:
                        Text("编码："+data[index].areaCode.toString(),style: new TextStyle(color: Color(0xFF333333),
                          fontSize: 12.0,
                        ),
                          maxLines: 10,
                          softWrap: true,
                        ),
                      ),

                    ],
                  ),
                ),


                Container(
                  padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:10),
                  child: Row(
                    crossAxisAlignment:CrossAxisAlignment.center,
                    children: [
                      Container(
                        width: rpx*550,
                      ),
                      Text(data[index].clocking==1?"已打卡":"未打卡",style: new TextStyle(color: Color(data[index].clocking==1?0xFF5DBF1E:0xFFF7003E),
                        fontSize: 12.0,
                      ),
                        maxLines: 3,
                        softWrap: true,),
                      Flexible(fit: FlexFit.tight, child: SizedBox()),

                    ],
                  ),
                ),
                Container(
                  height:0.5,
                  margin: EdgeInsets.only(left: 10,right: 10,top: 0,bottom: 0),
                  color: Colors.grey,
                ),
              ],
            ),
          );
        }
    );
  }
}